package com.blue.base.oauth.server.config.authorize.code;

import org.springframework.security.oauth2.common.util.RandomValueStringGenerator;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.code.JdbcAuthorizationCodeServices;

import javax.sql.DataSource;

/**
 * 授权码存取在数据库
 *
 * @author liulei
 * @version 1.0
 */
public class MyJdbcAuthorizationCodeServices extends JdbcAuthorizationCodeServices {

    public MyJdbcAuthorizationCodeServices(DataSource dataSource) {
        super(dataSource);
    }

    /**
     * 重写生成code
     *
     * @param authentication 认证信息
     * @return java.lang.String
     */
    @Override
    public String createAuthorizationCode(OAuth2Authentication authentication) {
        String code = new RandomValueStringGenerator().generate();
        store(code, authentication);
        return code;
    }
}
